package com.risen.project.enums;

import cn.hutool.core.util.StrUtil;

import java.util.Arrays;
import java.util.Optional;

/**
 * 立项依据枚举
 */
public enum ProjectBasisEnum  {

    PBE_STATE_MINISTRIES_ISSUED("1", "国家部委下达任务、相关文件明确建设时间"),

    PBE_LEADER_ISSUED("2", "本级及上级领导批示"),

    PBE_MAJOR_TASK("3", "重大任务"),

    PBE_MAJOR_COMMON_PROBLEM("4", "重大共性问题"),

    PBE_MAJOR_DECISION("5", "重大决策"),

    PBE_BENEFITS_ENTERPRISES_PEOPLE("6", "普惠性惠企利民"),

    PBE_OTHER("7", "其他")
    ;

    private final String code;
    private final String msg;

    ProjectBasisEnum(String code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public static String getMsgByCode(String code) {
        Optional<ProjectBasisEnum> optional = Arrays.stream(values())
                .filter(c -> c.code.equals(code))
                .findFirst();

        return optional.isPresent() ? optional.get().msg : "";
    }

    /**
     * 分割code拼接枚举结果方法
     * @param code 匹配code
     * @param split 分隔符
     * @return String
     */
    public static String getMsgByCodeSplit(String code, String split) {
        if (StrUtil.isEmpty(code)) {
            return "";
        }

        StringBuilder sb = new StringBuilder();
        String[] codeSplit = StrUtil.split(code, split);

        for (String cs : codeSplit) {
            Optional<ProjectBasisEnum> optional = Arrays.stream(values())
                    .filter(c -> c.code.equals(cs))
                    .findFirst();

            optional.ifPresent(projectStatusEnum -> sb.append(projectStatusEnum.msg).append(split));
        }

        return sb.toString();
    }
}
